<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var time_new = new Date();
      document.write("当前时间：");
      document.write(time_new.getFullYear() + "年"); // 获取年
      document.write(time_new.getMonth() + 1 + "月"); // 获取月
      document.write(time_new.getDate() + "日"); // 获取日
      document.write(
        time_new.getHours() + //获取时
          ":" +
          time_new.getMinutes() + //获取分
          ":" +
          time_new.getSeconds() // 获取秒
      );
    </script>
    <!-- 换行 -->
    <br />
    <!-- 用doc输出标题 -->
    <script>
      document.write("<h1>this is h1 title</h1>");
    </script>
    <!-- 修改title内容 -->
    <script>
      document.title = "title modified by bom object!";
    </script>
    <!-- 通过getElementById函数获取html页面中id=“box”的元素；
     -->
    <div id="box">this is a box</div>
    <div>
      <p class="class1">this is class1</p>
    </div>
    <p class="class1">this is class333</p>
    <script>
      var obj = document.getElementById("box");
      console.log(obj);
      document.write(obj.innerText);
    </script>
    <br />
    <!-- 通过getElementsByTagName函数获取html页面中所有div标签的元素；
     -->
    <script>
      var obj2 = document.getElementsByTagName("div");
      //    设置循环，从0开始，不大于obj2的长度,再加完
      for (i = 0; i <= obj2.length; i++) {
        document.write(obj2[i].innerHTML);
      }
    </script>
  </body>
</html>
